package cn.edu.ustc.xrovers.daoImpl;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import cn.edu.ustc.xrovers.dao.LoginDao;

/**
 * 用户登陆Dao实现类
 * @author paddy
 *
 */
public class LoginDaoImpl extends BaseDao implements LoginDao {
	
	/**
	 * 查找登陆用户
	 * @param username 用户名
	 * @param password 密码
	 * @param type 用户类型
	 * @return 用户信息的实体类对象
	 */
	public Object findUser(final String username, final String password, final String type) {
		Object result=ht.execute(new HibernateCallback<Object>() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query=session.createQuery("from "+type+" where "+type.toLowerCase()+"Id=:username and password=:password");
				query.setParameter("username",username);
				query.setParameter("password", password);
				return query.uniqueResult();
			}
		});
		return result;
	}
}
